package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import si.yun.common.ConstantEntity;
import si.yun.dao.SyBeforeUserMapper;
import si.yun.dao.SyCourseMapper;
import si.yun.dao.SyProductMapper;
import si.yun.dao.SyVideoCatalogueMapper;
import si.yun.service.SyTeacherSystemService;
import si.yun.utils.Utils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: 教师首页实现类
 * @Description: TODO
 * @Author: 柴秋生
 * @Date 2021/9/11 11:34
 */
@Service
public class SyTeacherSystemServiceImpl implements SyTeacherSystemService {
    @Autowired
    private SyCourseMapper syCourseMapper;
    @Autowired
    private SyBeforeUserMapper syBeforeUserMapper;
    @Autowired
    private SyVideoCatalogueMapper syVideoCatalogueMapper;
    @Autowired
    private SyProductMapper syProductMapper;
    /**
     * 系统首页——上传的视频浏览数
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:56
     * @Param : []
     * @Return : int
     */
    @Override
    public int selVideoLook() {

        int videoLook=syCourseMapper.selVideoLook();
        return videoLook;
    }
    /**
     * 系统首页——收藏量
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:57
     * @Param : []
     * @Return : int
     */
    @Override
    public int selVideoCollect() {
        int videoCollect=syCourseMapper.selVideoCollect();
        return videoCollect;
    }
    /**
     * 系统首页——点赞量
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:58
     * @Param : []
     * @Return : int
     */
    @Override
    public int selVideoLike() {
        int videoLike=syCourseMapper.selVideoLike();
        return videoLike;
    }
    /**
     * 系统首页——编译课程数
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:58
     * @Param : []
     * @Return : int
     */
    @Override
    public int selCourseCstatus() {
        int courseCstatus=syCourseMapper.selCourseCstatus();
        return courseCstatus;
    }
    /**
     *首页--已处理课程数
     * @Author : 柴秋生
     * @Date : 2021/9/17 8:56
     * @Param : []
     * @Return : int
     */
    @Override
    public int selAlreadyCourse() {
        int selAlreadyCourse=syCourseMapper.selAlreadyCourse();
        return selAlreadyCourse;
    }
    /**
     * 商品总览——课程数量（已上架）
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:58
     * @Param : []
     * @Return : int
     */
    @Override
    public int selCourseStatus() {
        int courseStatus=syCourseMapper.selCourseStatus();
        return courseStatus;
    }
        /**
     * 本月新增课程总数
     * @Author : 柴秋生
     * @Date : 2021/8/12 20:52
     * @Param : []
     * @Return : si.yun.utils.JsonData
     */
    @Override
    public int selCourseMonth() {
        int selCourseMonth=syCourseMapper.selCourseMonth();
        return selCourseMonth;
    }
    /**
     * 本月申请成功
     * @Author : 柴秋生
     * @Date : 2021/8/12 21:12
     * @Param : []
     * @Return : si.yun.utils.JsonData
     */
    @Override
    public int selSuccessfulApplication() {
        int selSuccessfulApplication=syCourseMapper.selSuccessfulApplication();
        return selSuccessfulApplication;
    }
    /**
     * 用户总览——今日新增用户总览量
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:39
     * @Param : []
     * @Return : int
     */
    @Override
    public int selUserOverviewToday() {
        int userOverviewToday=syBeforeUserMapper.selUserOverviewToday();
        return userOverviewToday;
    }
    /**
     * 用户总览——昨日新增用户总览量
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:44
     * @Param : []
     * @Return : int
     */
    @Override
    public int selUserOverviewYesterday() {
        int userOverviewYesterday=syBeforeUserMapper.selUserOverviewYesterday();
        return userOverviewYesterday;
    }
    /**
     *用户总览——本月新增用户总览量
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:45
     * @Param : []
     * @Return : int
     */
    @Override
    public int selUserOverviewMonth() {
        int userOverviewMonth=syBeforeUserMapper.selUserOverviewMonth();
        return userOverviewMonth;
    }
    /**
     *用户总览——全部用户
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:45
     * @Param : []
     * @Return : int
     */
    @Override
    public int selUserOverviewCount() {
        int userOverviewCount=syBeforeUserMapper.selUserOverviewCount();
        return userOverviewCount;
    }
    /**
     * 系统首页——上传视频总数
     * @Author : 柴秋生
     * @Date : 2021/8/3 20:00
     * @Param : []
     * @Return : int
     */
    @Override
    public int selVideoCount() {
        int videoCount=syVideoCatalogueMapper.selVideoCount();
        return videoCount;
    }
    /**
     * 首页——商品总览——商品数量（已上架）
     * @Author : 柴秋生
     * @Date : 2021/8/3 19:59
     * @Param :
     * @Return :
     */
    @Override
    public int selProductSate() {
        int productSate=syProductMapper.selProductSate();
        return productSate;
    }
    /**
     * 上月新增课程总数
     * @Author : 柴秋生
     * @Date : 2021/9/14 10:34
     * @Param : []
     * @Return : int
     */
    @Override
    public int selCourseLastMonth() {
        int selCourseLastMonth=syCourseMapper.selCourseLastMonth();
        return selCourseLastMonth;
    }
    /**
     * 上月申请成功
     * @Author : 柴秋生
     * @Date : 2021/9/14 10:34
     * @Param : []
     * @Return : int
     */
    @Override
    public int selLastApplication() {
        int selLastApplication=syCourseMapper.selLastApplication();
        return selLastApplication;
    }
    /**
     * @Author : 李振海
     * @Date : 2021/9/10 8:49
     * @Param : [name]
     * @Return : java.util.Map<java.lang.String,java.lang.Object>
     *     获取所有统计图数据
     */
    @Override
    public Map<String,Object> selCurriculumCount(String name) throws ParseException {
        //获取周日期
        List<String> week = Utils.getWeek();
        Map<String,Object> map=new HashMap<>();
        //周
        List li1 = li(week,name);
        List list1 = li1(week,1);
        //日
        List<String> day = Utils.getDay(1);
        day.remove(day.size()-1);
        List li2 = li(day,name);
        List<String> day1 = Utils.getDay(0);
        List list2 = li1(day1,2);
        //周
        map.put("week",li1);
        map.put("weekData",list1);
        //日
        map.put("day",li2);
        map.put("dayData",list2);
        //月
        List<Integer> month = Utils.getMonth();
        List<String> dayListOfMonth = Utils.getDayListOfMonth(0);
        String perFirstDayOfMonth = Utils.getPerFirstDayOfMonth();
        List<String> i=new ArrayList<>();
        i.addAll(dayListOfMonth);
        i.add(perFirstDayOfMonth);
        List li3 = li(i,name);
        //月
        map.put("month",li3);
        map.put("monthData",month);
        return map;
    }
    /**
     * @Author : 李振海
     * @Date : 2021/9/8 11:48
     * @Param : [week]
     * @Return : java.util.List
     * 处理日期减1
     */
    public List li1(List<String> week,int a){
        List<String> list=new ArrayList<>();
        for (int i = 0; i <week.size() - a; i++) {
            list.add(week.get(i));
        }
        return list;
    }
    /**
     * @Author : 李振海
     * @Date : 2021/9/8 11:48
     * @Param : [week]
     * @Return : java.util.List
     * 获取日期相对应数据
     */
    public List li(List<String> week,String name){
        String i = null;
        List<String> list=new ArrayList<>();
        for(int a=0;a<week.size()-1;a++){
            String s = week.get(a);
            String s1 = week.get(a + 1);
            if(name.equals("FeedbackStatistics")){//系统首页统计图
                i=syCourseMapper.selCurriculumCount(s,s1);
                list.add(i);
            }else if(name.equals("CommodityPurchaseStatistics")){//商品订单统计CommodityPurchaseStatistics
                i=syCourseMapper.CommodityPurchaseStatistics(s,s1,3,6);
                list.add(i);
            }else if(name.equals("CoursePurchaseStatistics")){//课程订单统计CoursePurchaseStatistics
                i=syCourseMapper.CoursePurchaseStatistics(s,s1,2,6);
                list.add(i);
            }


        }
        return list;
    }

    //获取课程订单总数
    @Override
    public Map<String, Object> getCountCommodity() {
        String total=syCourseMapper.getCountCommodity( ConstantEntity.THREE,ConstantEntity.SIX);
        String total1=syCourseMapper.getCountCommodity1( ConstantEntity.THREE,ConstantEntity.SIX);
        Map<String,Object> m=new HashMap<>();
        m.put("total",total);
        m.put("total1",total1);
        return m;
    }

    @Override
    public Map<String, Object> CoursePurchaseStatistics1() {
        String total = syCourseMapper.getCountCommodity(2, 6);
        String total1=syCourseMapper.getCountCommodity1(2,6);
        Map<String,Object> m=new HashMap<>();
        m.put("total",total);
        m.put("total1",total1);
        return m;
    }



}
